<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>{$goods.goods_name} {$name} {$seo_title} {$site_name}</title>
	<meta name="keywords" content="{$goods.keywords}" />
	<meta name="description" content="{$goods.good_desc}">
	<tc_include file="Public:head" />
	<script type="text/javascript" src="__TMPL__Public/assets/js/jquery.jqzoom.js"></script>
	<script type="text/javascript" src="__TMPL__Public/assets/js/base.js"></script>
</head>
<body>
	<!---头部开始--->
	<tc_include file="Public:header"/>
	<!---头部结束--->
	<div class="k-bd-default">
		<div class="k-row">
			<!---面包屑--->
			<div class="crumbs">
				<a href="/">首页</a><i class="fa fa-angle-right"></i>
			<foreach name="crumbs" item="vo">
				<a href="{:U('list/index',array('id'=>$vo['id']))}">{$vo['name']}</a><i class="fa fa-angle-right"></i>
			</foreach>
				<span class="k-cur">{$category}</span>
			</div>
		</div>
		<!---详情上--->
		<div class="default-bd">
		
			<input type="hidden" value="{$goods.goods_id}" name="goods_id" />
			<div class="k-bd">
				<div class="default-top">
					<div class="silde fl">
						<div id="preview" class="spec-preview"> <span class="jqzoom"><img jqimg="{:sp_get_asset_upload_path($first_photo['url'])}" src="{:sp_get_asset_upload_path($first_photo['url'])}" /></span> </div>
						<!--缩图开始-->
							<div class="spec-scroll"> 
							  <div class="items">
								<ul>
								<foreach name="photo" item="vo">
								  <li><img alt="{$goods.goods_name}" bimg="{:sp_get_asset_upload_path($vo['url'])}" src="{:sp_get_asset_upload_path($vo['url'])}" onmousemove="preview(this);"></li>
								</foreach>								  
								</ul>
							  </div>
							</div>
					</div>
					<!--缩图结束-->
					<div class="info fr">
						<div class="name">
							{$goods.goods_name}
						</div>
						<div class="desc">{$goods.goods_remark}</div>
						<div class="price-wrap">
							<div class="filed gprice">
								<span class="label">售价</span>
								<span><span class="r-yen">¥</span><span class="j-price" id="j-goods-price">{$goods.shop_price}</span></span>
								<span class="j-mprice"><if condition="$goods.market_price neq 0">¥{$goods.market_price}</if></span>
							</div>
							<div class="filed sale">
								<span class="label">促销</span>
								<span>暂无促销</span>
							</div>
							<div class="filed shipp">
								<span class="label">运费</span>
								<span>全场包邮</span>
							</div>
						</div>
						<form action="" id="buy_goods_form">
							<!--规格-->
							<foreach name="sku" item="vo" key="k">							
							<div class="j-filed j-spec">
								<span class="f-name fl">{$k}</span>
								<div class="fl">
									<ul>
										<php>sort($vo);</php>
										<foreach name="vo" item="val">
										<if condition="$val['img'] eq null">
										<li class="spec-box spec-item-tx"><a href="javascript:;" onClick="switch_spec_text(this)"><span>{$val.item}</span><span class="sku-icon"></span></a><input type="radio" style="display:none;" name="goods_spec[{$k}]" value="{$val[item_id]}" /></li>
										<else />
										<li class="spec-box spec-item-img"><a href="javascript:;" onClick="switch_spec_img(this)"><img src="{:sp_get_image_preview_url($val['img'])}" onClick="$('#preview').find('img').attr('src','{:sp_get_image_preview_url($val['img'])}'),$('#preview').find('img').attr('jqimg','{:sp_get_image_preview_url($val['img'])}')" width=45 title="{$val.item}" alt="" /><span class="sku-icon"></span></a><input type="radio" style="display:none;" name="goods_spec[{$k}]" value="{$val[item_id]}" /></li>
										</if>
										</foreach>
									</ul>
								</div>
							</div>
							<div class="clear"></div>
							</foreach>
							<!--数量-->
							<div class="j-filed j-num">
								<span class="fl f-name">数量</span>
								<div class="selnum fl">
									<span class="j-reduce" onClick="switch_num(-1);"><i class="fa fa-minus"></i></span>
									<input class="j-input" type="text" value="1" name="goods_num" id="goods_num" />
									<span class="j-add" onClick="switch_num(1);"><i class="fa fa-plus"></i></span>
								</div>							
							</div>
							<div class="clear"></div>
							<div class="btns">
								<a href="javascript:;" onclick="AjaxAddCart({$goods.goods_id},1)" class="btn g-buy">立即购买</a>
								<a href="javascript:;" class="btn g-cart" onClick="javascript:AjaxAddCart({$goods.goods_id},0);"><i class="fa fa-shopping-cart"></i> 加入购物车</a>
							</div>							
						</form>
					</div>				
				</div>
				<div class="clear"></div>
				<div class="bt-bd">
						<div class="left fl">
							<div class="title">
								<h3>热门推荐</h3>
							</div>
							<ul>
							<foreach name="side_goods" item="vo">
								<li>
									<div class="d-pic"><a href="{:U('Goods/article/index',array('g_id'=>$vo['goods_id']))}" title="{$vo.goods_name}" target="_blank"><img src="{:sp_get_asset_upload_path($vo[goods_img])}" alt="{$vo.goods_name}" /></a></div>
									<div class="d-name"><a href="{:U('Goods/article/index',array('g_id'=>$vo['goods_id']))}" title="{$vo.goods_name}" target="_blank">{$vo.goods_name|msubstr=0,40,'utf-8',''}</a></div>
									<div class="d-price"><strong class="xh">￥{$vo.shop_price}</strong></div>
								</li>
							</foreach>
							</ul>
						</div>
						<div class="right fr">
							<div class="d-bt-nav">
								<ul class="d-bt-ul">
									<li class="active">商品介绍</li>
									<li>评价 <span class="xh" style="font-size:14px;">({$goods.comment_count})</span></li>									
								</ul>
							</div>
							<div class="clear"></div>
							<div class="d-bd">
								<div class="d-content active">
									<div class="content">
										{$goods.goods_content}
									</div>									
								</div>
								<div class="d-content">
									<div class="s-comment">
										<div class="s-radio fl">											
											<label for="all-comment"><input type="radio" class="ra-comment" id="all-comment" name="catcomment" value="0" checked="checked" />全部 ({$all_count})</label>
										</div>
										<div class="s-radio fl">											
											<label for="ipc-comment"><input type="radio" class="ra-comment" id="ipc-comment" name="catcomment" value="1" />有图 ({$pic_count})</label>
										</div>
										<div id="c_type" data-type="0"></div>
									</div>
									<div class="clear"></div>
									<div class="comment-list" id="comment_list">
										<!--加载评论-->
									</div>
								</div>
							</div>																					
						</div>
						<div class="clear"></div>
				</div>				
			</div>		
		</div>					
	</div>
	<tc_include file="Public:footer" />
	
	<script type="text/javascript">
		$(document).ready(function(){
            //_type = 0; // 评论类型
            commentList(0,1);// 加载评价列表
        });
		
		$(".ra-comment").click(function(){
			var _type = $(this).val();
			$("#c_type").attr('data-type',_type);
			commentList(_type,1);
		});
		
		function commentList(_type,page){
			$.ajax({
                    type : "GET",
                    url:"/index.php?g=Goods&m=article&a=commentList&goods_id={$goods['goods_id']}&commentType="+_type+"&p="+page,
                    success: function(data){
                     $("#comment_list").html('');
                     $("#comment_list").append(data);
                }
            });
		}
	</script>
	
	<script type="text/javascript">
		function switch_spec_text(spec)
		{
			$(spec).siblings('input').trigger('click');	 // 让隐藏的 单选按钮选中
			$(spec).parent().parent().find('.spec-item-tx').removeClass('sku-item'); //   清空勾选图标
			$(spec).parent().addClass('sku-item'); // 当前 加上勾选图标
			// 更新商品价格
			$(spec).parent().parent().parent().parent().siblings('.j-spec').addClass('asdf');
			get_goods_price();
		}
		function switch_spec_img(spec)
		{
			$(spec).siblings('input').trigger('click');	 // 让隐藏的 单选按钮选中
			$(spec).parent().parent().find('.spec-item-img').removeClass('sku-item-img'); //   清空勾选图标
			$(spec).parent().addClass('sku-item-img'); // 当前 加上勾选图标
			// 更新商品价格
			get_goods_price();
		}
	</script>
	
	<script type="text/javascript">
		var _num = $("#goods_num").val();
		if(_num = 1){
			$(".j-reduce").addClass('disabled');
		}
		function switch_num(num)
		{
			var num2 = parseInt($("#goods_num").val());
			num2 += num;
			if(num2 < 1) num2 = 1; // 保证购买数量不能少于 1
			if(num2 > 1){
				$(".j-reduce").removeClass('disabled');
			}
			if(num2 <= 1){
				$(".j-reduce").addClass('disabled');
			}
			$("#goods_num").val(num2); // 修改商品购买数量
			// 更新商品价格
			//get_goods_price();
		}
	</script>
	<script type="text/javascript">
		// 用作 sort 排序用
		function sortNumber(a,b)
		{
			return a - b;
		}
		//查询商品价格
		function get_goods_price()
		{

			//var goods_price = {$goods.shop_price}; // 商品起始价
			//var store_count = {$goods.store_count}; // 商品起始库存

			var sku_goods_price = {$sku_goods_price};  // 规格 对应 价格 库存表
			// 如果有属性选择项
			//alert(sku_goods_price);
			if(sku_goods_price != null)
			{
				goods_spec_arr = new Array();
				$("input[name^='goods_spec']:checked").each(function(){
					goods_spec_arr.push($(this).val());
				});
				var spec_key = goods_spec_arr.sort(sortNumber).join('-');  //排序后组合成 key
				
				if(sku_goods_price.hasOwnProperty(spec_key) == true){
					//判断key是否存在
					var goods_price = sku_goods_price[spec_key]['price']; // 找到对应规格的价格				
					var store_count = sku_goods_price[spec_key]['store_count']; // 找到对应规格的库存
				}			
			}
			
			if(store_count <=0){
				//alert('no');
			}
			/*var goods_num = parseInt($("#goods_num").val());
			// 库存不足的情况
			if(goods_num > store_count)
			{
				goods_num = store_count;
				layer.msg('库存仅剩 '+store_count+' 件', {icon: 2}); //alert('库存仅剩 '+store_count+' 件');
				//$("#goods_num").val(goods_num);
			}*/

			var flash_sale_price = parseFloat("{$goods['flash_sale']['price']}");
			(flash_sale_price > 0) && (goods_price = flash_sale_price);

			$("#j-goods-price").html(goods_price); // 变动价格显示
		}
	</script>
	
		<script type="text/javascript">
		 /**
 * addcart 将商品加入购物车
 * @goods_id  商品id
 * @num   商品数量
 * @form_id  商品详情页所在的 form表单
 * @to_catr 加入购物车后再跳转到 购物车页面 默认不跳转 1 为跳转
 */
function AjaxAddCart(goods_id,to_catr)
{								
				var goods_spec = new Array();				
				$("input[name^='goods_spec']:checked").each(function(){
					goods_spec.push($(this).val());
				});	
				var _num = $("input[name='goods_num']").val();				
				if(to_catr == 1){					
						$.post("{:U('user/index/is_login')}",{},function(data){
							if(data.status==1){		
								layer.closeAll();
								//window.location.href="{:U('Goods/Cart/cart_buy',array('to_buy'=>'buy','goodsid'=>"+goods_id+"))}";			
								//window.location.href="/index.php?g=goods&m=cart&a=cart_buy&to_buy=buy&goods_id="+goods_id;
								$.ajax({
										type : "POST",
										url:"{:U('Cart/cart_buy')}",
										data : {goods_id:goods_id,goods_num:_num,goods_spec:goods_spec},                        
										dataType:'json',
										success: function(data){
											if(data.status > 0){
												window.location.href="{:U('Goods/Cart/cart_buy',array('top_buy'=>'buy'))}";	
											}else{
												layer.msg(data.msg);
											}
											
										}
								});
							}
							if(data.status==0){
								var _html = "{:U('User/login/layerlogin')}";		
								layer.open({
								type: 2,
								title: '登录',
								shadeClose: true,
								shade: 0.8,
								area: ['385px', '460px'],
								content: _html,
								});	
							}				
						});		
				}else{
					$.ajax({
							type : "POST",
							url:"{:U('Cart/ajaxAddCart')}",
							data : {goods_id:goods_id,goods_num:_num,goods_spec:goods_spec},// 你的formid 搜索表单 序列化提交                        
							dataType:'json',
							success: function(data){
								
									if(data.status > 0){
										cart_num = parseInt($('#cart_quantity').html())+parseInt($('input[name="goods_num"]').val());
										$('#cart_quantity').html(cart_num);
																			
										$.ajax({
											type : "GET",
											url:"{:U('Cart/header_cart_list')}",//+tab,
											success: function(data){				
												$("#header_cart_list > .micart > .ris").html(data);	
												get_cart_num();
											}
										});
										$(".j-mini-cart").fadeIn().delay(3000).fadeOut();
									}else{
										
										layer.msg(data.msg);
									}
										
									
							}
					});  
				}
				
}

	</script>
	<script type="text/javascript">
	$(function(){
		//$(".d-bt-ul li:first").addClass('active');
		 $(".d-bt-ul li").click(function(){
			 $(this).addClass("active").siblings().removeClass("active"); 
			 var index=$(this).index(); 
			 $(".d-bd > .d-content").eq(index).show().siblings().hide(); 
		 });
	});
	</script>

<tc_include file="Public:scripts" />
</body>